<!DOCTYPE HTML>
<html  lang="zh" xmlns:th="http://www.thymeleaf.org">
<meta charset="utf-8">
<head th:include="include :: header"></head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-lecture-edit" th:object="${lecture}" >
            <input id="lectureId" name="lectureId" th:field="*{lectureId}"  type="hidden">
            <input name="deptId"  type="hidden"  th:field="*{deptId}" id="treeId"/>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门名称：</label>
                <div class="col-sm-8">
                    <input class="form-control" type="text" name="deptName" onclick="selectDeptTree()" readonly="true" id="treeName" th:field="*{deptName}">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">老师id：</label>
                <div class="col-sm-8">
                    <input id="teacherId" name="teacherId" th:field="*{teacherId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">老师姓名：</label>
                <div class="col-sm-8">
                    <input id="teacherName" name="teacherName" th:field="*{teacherName}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学生id：</label>
                <div class="col-sm-8">
                    <input id="userId" name="userId" th:field="*{userId}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">学生姓名：</label>
                <div class="col-sm-8">
                    <input id="userName" name="userName" th:field="*{userName}" class="form-control" type="text">
                </div>
            </div>
            <!--<div class="form-group">
                <label class="col-sm-3 control-label">上课日期：</label>
                <div class="col-sm-8">
                    <input id="classtime" name="classtime" th:field="*{classtime}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">上课时间：</label>
                <div class="col-sm-8">
                    <input id="createTime" name="createTime" th:field="*{createTime}" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">下课时间：</label>
                <div class="col-sm-8">
                    <input id="endTime" name="endTime" th:field="*{endTime}" class="form-control" type="text">
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">歌曲名：</label>
                <div class="col-sm-8">
                    <input id="songName" name="songName" th:field="*{songName}" class="form-control" type="text" onclick="selectSong()" readonly="true">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">级别：</label>
                <div class="col-sm-8">
                    <input id="songLevel" name="songLevel" th:field="*{songLevel}" class="form-control" type="text" readonly="true">
                </div>
            </div>
            <!--
            <div class="form-group">
                <label class="col-sm-3 control-label">级别：</label>
                <div class="col-sm-8">
                    <select id="songLevel" class="form-control m-b" th:with="type=${@dict.getType('zl_subject_level')}">
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:data-remake="${dict.remark}" th:field="*{songLevel}"></option>
                    </select>
                </div>
            </div>-->
            <div class="form-group">
                <label class="col-sm-3 control-label">课时费：</label>
                <div class="col-sm-8">
                    <input id="hourSubsidy" name="hourSubsidy" th:field="*{hourSubsidy}" class="form-control" type="text" readonly  unselectable="on">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">备注：</label>
                <div class="col-sm-8">
                    <input id="remark" name="remark" th:field="*{remark}" class="form-control" type="text">
                </div>
            </div>
		</form>
    </div>
    <div th:include="include::footer"></div>
    <script type="text/javascript">
        /**
        var options_level_class = eval("[[${@dict.getTypeJson('zl_subject_level')}]]".replace(/&quot;/g, "'"));
        var options;
        var _options_html = "";
        options=options_level_class;
        for (var i = 0; i < options.length; i++) {
            var option = options[i];
            console.log(option)
            _options_html = _options_html + "<option value='" + option.dictValue + "' data-remark='"+option.remark+"'>" +  option.dictLabel + "</option>"
        }

        $("#songLevel").html(_options_html);
        $("#hourSubsidy").val($("#songLevel option:selected").attr("data-remark"))

        $("#hourSubsidy").val($("#songLevel option:selected").attr("data-remark"))
        $("#songLevel").on("change", function () {
            $("#hourSubsidy").val($("#songLevel option:selected").attr("data-remark"))
        })**/

		var prefix = ctx + "project/lecture"
		$("#form-lecture-edit").validate({
			rules:{
				xxxx:{
					required:true,
				},
			}
		});

        function submitHandler() {
            if ($.validate.form()) {
                edit();
            }
        }

        function edit() {
            var deptId = $("input[name='deptId']").val();
            var deptName = $("input[name='deptName']").val();

            var lectureId = $("input[name='lectureId']").val();
            var teacherId = $("input[name='teacherId']").val();
            var teacherName = $("input[name='teacherName']").val();
            var userId = $("input[name='userId']").val();
            var userName = $("input[name='userName']").val();
            var songName = $("input[name='songName']").val();
            var hourSubsidy = $("input[name='hourSubsidy']").val();
            var remark = $("input[name='remark']").val();
            //var songLevel = $("#songLevel option:selected").val();
            var songLevel = $("input[name='songLevel']").val();

            $.ajax({
                cache : true,
                type : "POST",
                url : ctx + "project/lecture/edit",
                data : {
                    "deptId": deptId,
                    "deptName": deptName,

                    "lectureId": lectureId,
                    "teacherId": teacherId,
                    "teacherName": teacherName,
                    "userId": userId,
                    "userName": userName,
                    "songName": songName,
                    "hourSubsidy": hourSubsidy,
                    "remark": remark,
                    "songLevel": songLevel,

                },
                async : false,
                error : function(request) {
                    $.modal.alertError("系统错误");
                },
                success : function(data) {
                    $.operate.saveSuccess(data);
                }
            });
        }

        /*用户管理-新增-选择部门树*/
        function selectDeptTree() {
            var treeId = $("#treeId").val();
            var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
            var url = ctx + "system/dept/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: ctx + "system/dept/selectDeptTree/" + deptId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        }

        function doSubmit(index, layero){
            var tree = layero.find("iframe")[0].contentWindow.$._tree;
            if ($.tree.notAllowParents(tree)) {
                var body = layer.getChildFrame('body', index);
                $("#treeId").val(body.find('#treeId').val());
                $("#treeName").val(body.find('#treeName').val());
                layer.close(index);
            }
        }
        //选择歌曲
        function selectSong() {
            var options = {
                title: '选择歌曲',
                width: "600",
                url: ctx + "project/song/data",
                callBack: selectSongCallBack
            };
            $.modal.openOptions(options);
        }
        function selectSongCallBack(index, layero) {
            var body = layer.getChildFrame('body', index)
            $("#songName").val(body.find('.selected td:nth-child(3)').text());
            $("#songLevel").val(body.find('.selected td:nth-child(5)').text());
            $("#hourSubsidy").val(body.find('.selected td:nth-child(6)').text());
            layer.close(index)
        }
	</script>
</body>
</html>
